<script setup lang="ts">
import { setting } from '@/store/common/setting.ts';
import { reactive } from 'vue';
import { LoginForm } from '@/types/user/UserTypes.ts';
import { userLogin } from '@/api/user';
import PortalButton from '@/components/form/button/PortalButton.vue';
import PortalInput from '@/components/form/input/PortalInput.vue';
const loginForm = reactive<LoginForm>({
  username: '',
  password: '',
  code: '',
  uuid: '',
});
const defaultSetting = setting();
const { code, initCode, customLogin } = userLogin();
</script>
<template>
  <div class="login">
    <div class="login-content left">
      <div class="login-content-header">
        <img :src="defaultSetting.$state.logoBg" alt="加载失败" />
      </div>
      <div class="login-svg">
        <svg-icon name="icon-com-login" :icon-style="{ width: '100%', height: '100%' }" />
      </div>
    </div>
    <div class="login-content right">
      <div class="login-content-header">用户登录</div>
      <div class="login-body">
        <div class="login-menu">
          <div class="login-menu-li active">账号登录</div>
        </div>
        <div class="login-form">
          <div class="login-form-item">
            <portal-input
              v-model="loginForm.username"
              :rule="{ req: true, message: '登录账号不能为空！' }"
              placeholder="请输入登录账号"
              icon-prefix="icon-com-username"
            />
          </div>
          <div class="login-form-item">
            <portal-input
              v-model="loginForm.password"
              :rule="{ req: true, message: '登录密码不能为空！' }"
              type="password"
              placeholder="请输入登录密码"
              icon-prefix="icon-com-password"
            />
          </div>
          <div class="login-form-item">
            <div class="form-input-code">
              <portal-input
                v-model="loginForm.code"
                :rule="{ req: true, message: '验证码不能为空！' }"
                placeholder="请输入验证码"
                icon-prefix="icon-com-code"
              />
            </div>
            <div class="form-input-image" @click="initCode">
              <img :src="code.img" alt="加载失败" />
            </div>
          </div>
          <div class="login-form-item">
            <portal-button theme="primary" @click="customLogin(loginForm, code)"> 登&nbsp;&nbsp;录 </portal-button>
          </div>
        </div>
        <div class="login-footer">
          地址：上海市浦东新区东方路688号 电话：021-60756317<br />
          ©2021 by 上海亿维航软件有限公司 沪ICP备19008161号-1
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-size: cover;
  .login-content {
    width: 50%;
    height: 100%;
    position: relative;
    padding: 60px 0;
    box-sizing: border-box;
    .login-content-header {
      width: 100%;
      height: 60px;
      padding: 0 60px;
      box-sizing: border-box;
      line-height: 60px;
      text-align: left;
      img {
        height: 60px;
      }
    }
    .login-svg {
      width: 100%;
      height: calc(100% - 60px);
    }
  }
  .login-content.left {
    background-color: #4393fa;
  }
  .login-content.right {
    display: flex;
    flex-flow: column nowrap;
    .login-content-header {
      background: linear-gradient(90deg, #cbe1ff 20%, #fff);
      text-align: center;
      font-size: 1.5rem;
      letter-spacing: 2px;
      color: var(--edu-text-200);
    }
    .login-body {
      flex: 1 1;
      width: 100%;
      padding-top: 60px;
      padding-left: 20%;
      padding-right: 20%;
      box-sizing: border-box;
      display: flex;
      flex-flow: column nowrap;
      .login-menu {
        width: 100%;
        height: 45px;
        border-bottom: 1px solid #dcdfe6;
        display: flex;
        align-items: center;
        .login-menu-li {
          width: 33.333%;
          text-align: center;
          height: 45px;
          cursor: pointer;
          font-size: 1.1rem;
          position: relative;
          line-height: 30px;
        }
        .login-menu-li.active {
          color: var(--edu-primary-200);
        }
        .login-menu-li.active::before {
          content: '';
          position: absolute;
          height: 2px;
          left: 2px;
          right: 2px;
          bottom: 0;
          background-color: var(--edu-primary-200);
        }
      }
      .login-form {
        width: 100%;
        flex: 1 1;
        .login-form-item {
          width: 100%;
          height: 60px;
          padding: 10px 0;
          box-sizing: border-box;
          margin-top: 10px;
          display: flex;
          flex-flow: row nowrap;
          align-items: center;
          .form-input-code {
            flex: 1 1;
            height: 100%;
          }
          .form-input-image {
            width: 150px;
            height: 100%;
          }
        }
      }
      .login-footer {
        min-height: 60px;
        line-height: 30px;
        text-align: center;
        color: var(--edu-text-200);
      }
    }
  }
}
</style>
